version: '3.8'

services:
  keycloak:
    container_name: keycloak
    image: jboss/keycloak
    restart: always
    environment:
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
      DB_VENDOR: postgres
      DB_ADDR: postgres
      DB_DATABASE: keycloak
      DB_USER: postgres
      DB_PASSWORD: postgres
#    volumes:
#      - ./config/keycloak/realm-export.json:/opt/jboss/keycloak/realm-export.json
    command:
      - "-b 0.0.0.0"
#      - "-Dkeycloak.import=/opt/jboss/keycloak/realm-export.json"
#      - "-Dkeycloak.profile.feature.scripts=enabled"
#      - "-Dkeycloak.profile.feature.upload_scripts=enabled"
    ports:
      - "8080:8080"
    depends_on:
      - postgres
    networks:
      - flowing

  postgres:
    container_name: postgres
    image: postgres:latest
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: "postgres"
    command:
      # configuration for logging. All this config properties we can also set in postgres.conf.conf
      - "postgres"
      - "-c"
      - "log_statement=all"
      - "-c"
      - "log_directory=log"
      - "-c"
      - "log_filename=postgresql-%Y-%m-%d_%H%M%S.log"
      - "-c"
      - "logging_collector=on"
      - "-c"
      - "log_min_error_statement=error"
      - "-c"
      - "log_rotation_age=60"
    volumes:
      # If you need access to postgres data, uncomment this part
      # - pgdata:/var/lib/postgresql/data
      # - pgconf:/etc/postgresql
      # - pglog:/var/log/postgresql
      - ./config/postgres/init_scripts:/docker-entrypoint-initdb.d
    networks:
      - flowing
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U postgres" ]
      interval: 10s
      timeout: 5s
      retries: 5

  zookeeper:
    container_name: zookeeper
    image: "confluentinc/cp-zookeeper:latest"
    hostname: zookeeper
    networks:
      - flowing
    ports:
      - 2181:2181
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181

  kafka:
    container_name: kafka
    image: "confluentinc/cp-kafka:latest"
    hostname: kafka
    depends_on:
      - zookeeper
    networks:
      - flowing
    ports:
      - 9092:9092
      - 29092:29092
    environment:
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_LISTENERS: "INTERNAL://:29092,EXTERNAL://:9092"
      KAFKA_ADVERTISED_LISTENERS: "INTERNAL://kafka:29092,EXTERNAL://localhost:9092"
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT"
      KAFKA_INTER_BROKER_LISTENER_NAME: "INTERNAL"
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1

networks:
  flowing:
    external: true